

import java.lang.String;


//HoleCardRanker.java
// simple hole-card pre-flop pair ranker
// Benjamin Jeffery
// CS383.GradUnit
// 10/02/12

// input: hole cards: (card1 card2)
// output: int strRank (9 high to 1 low)
//
// preFlop rank list adapted from http://www.codeispoetry.org/poker/pre_flop
// checked and corrected from preflophands.com
// Hole card strength ranks adapted from Sklansky as per Wikipedia, but inverted

public class HoleCardRanker {
	
	  public static void main(String args[]){
		  // test case
		  
		  Card c1 = new Card(36);
		  Card c2 = new Card(47);
		  
		 System.out.println(HoleCardRanker.rankPair(c1, c2));

	  }
	  
	  public static int rankPair( Card c1, Card c2 ){
		  int HoleRank = 0;
		  int strRank;
		  String r1, r2, r10, r20;
		  int s1, s2;
		  String myHoleCards = "";
		  
		  final String pairRankList[] = {
			"AA","KK","QQ","AKs","JJ","AQs","KQs","AJs","KJs","TT","AK","ATs","QJs","KTs","QTs","JTs","99","AQ",
			"A9s","KQ","88","K9s","T9s","A8s","Q9s","J9s","AJ","A5s","77","A7s","KJ","A4s","A3s","A6s","QJ","66",
			"K8s","T8s","A2s","98s","J8s","AT","Q8s","K7s","KT","55","JT","87s","QT","44","33","22","K6s","97s",
			"K5s","76s","T7s","K4s","K3s","K2s","Q7s","86s","65s","J7s","54s","Q6s","75s","96s","Q5s","64s","Q4s",
			"Q3s","T9","T6s","Q2s","A9","53s","85s","J6s","J9","K9","J5s","Q9","43s","74s","J4s","J3s","95s","J2s",
			"63s","A8","52s","T5s","84s","T4s","T3s","42s","T2s","98","T8","A5","A7","73s","A4","32s","94s","93s",
			"J8","A3","62s","92s","K8","A6","87","Q8","83s","A2","82s","97","72s","76","K7","65","T7","K6","86",
			"54","K5","J7","75","Q7","K4","K3","96","K2","64","Q6","53","85","T6","Q5","43","Q4","Q3","74","Q2",
			"J6","63","J5","95","52","J4","J3","42","J2","84","T5","T4","32","T3","73","T2","62","94","93","92",
			"83","82","72"};
	
		  //private HoleCards constructor
		  // make an object from the rank string part of Card1 and Card2;
		  //concatenate an "s" if the Card1 and Card2 are of the same suit
		  // compare c2 & c2, higher rank goes first
		  if ( c1.getRank() < c2.getRank() ) {
			  Card temp;
			  temp = c1;
			  c1 = c2;
			  c2 = temp;
		  }

		  r1 = c1.toString();
		  r2 = c2.toString();
		  //System.out.println( r1 + r2 );	// good
		  
		  r10 = r1.substring(0, 1);
		  r20 = r2.substring(0, 1);

		  myHoleCards += r10;
		  myHoleCards += r20;
	
		  //suited? are the cards the same suit?
		  s1 = c1.getSuit();
		  s2 = c2.getSuit();  
		  if ( s1 == s2 )
		  		myHoleCards += "s";
		  
		  //System.out.println( "myHoleCards = " + myHoleCards);	// good
	 
		  //match the HoleCard to the PairRank index, iterate through the list
		  int i;
		  for ( i = 0; i < (pairRankList.length); i++ ) {
			  //System.out.println("i " + i + " " + myHoleCards + " " + pairRankList[i] );	// good
			  if (myHoleCards.equals(pairRankList[i])) {
				  //System.out.println( myHoleCards + " and " + pairRankList[i] );	//good
				  HoleRank = i;
			  }
		  }
		  
		  //System.out.println( "HoleRank is " + HoleRank );	//good
	 

// selection of strength rank
	if ( 0 <= HoleRank && HoleRank <= 4 )
		strRank = 9;
	else
		if ( 5 <= HoleRank && HoleRank <= 10 )
			strRank = 8;
		else
			if ( 11 <= HoleRank && HoleRank <= 16 )
				strRank = 7;
			else
				if ( 17 <= HoleRank && HoleRank <= 24 )
					strRank = 6;
				else
					if ( 25 <= HoleRank && HoleRank <= 42 )
						strRank = 5;
					else
						if ( 43 <= HoleRank && HoleRank <= 53 )
							strRank = 4;
						else
							if ( 54 <= HoleRank && HoleRank <= 73 )
								strRank = 3;
							else
								if ( 74 <= HoleRank && HoleRank <= 89 )
									strRank = 2;
								else
									strRank = 1;
	return strRank;
										

			
			// indexOf(HoleCards)
			//	Sklanky hand strength ranks are inverted
			//list index 0-4: rank 9; EV in real bets: 2.32 - 0.78
			// index 5-10: rank 8				       0.59 - 0.38
			// index 11-16: rank 7					   0.32 - 0.20
			// index 17-24 rank 6					   0.19 - 0.15
			// index 25-42 rank 5					   0.10 - 0.08
			// index 43-53 rank 4					   0.08 - 0.05
			// index 54-73 rank 3					   0.04 - 0.01
			// index 74-89 rank 2					   0.00
			// index 90-168 rank 1				   (-) 0.02 - 0.03
	
	
	}
}
